<!--
 * @Author: ChunLai
 * @Date: 2022-04-15 10:45:11
 * @LastEditTime: 2025-09-12 10:38:41
 * @Description: 签名操作弹窗
 * @FilePath: \02.bldinsure\src\views\prenotice\components\ShareMask.vue
-->
<template>
  <div class="mask">
    <div class="_modal">
      <div class="_modal-header">
        <div class="flex-lr">
          <span class="lineh1">告知填写</span>
          <MsImgIcon name="cross" @click.native="cancelClick()" />
        </div>
        <div class="p_label">为了保证合规性，请确认是客户本人填写的信息</div>
      </div>
      <div class="_modal-content">
        <div class="pic_sign"></div>
      </div>
      <div class="_modal-footer">
        <span> <span class="name_c ftw5">客户</span> 在身边？</span>
        <span class="_model_btn" @click="signNow()">立即填写</span>
      </div>
      <div class="_modal-footer mt10">
        <span> <span class="name_c ftw5">客户</span> 不在身边？</span>
        <span class="_model_btn" @click="copySignLink()">
          {{ origin == "ms" ? "分享给Ta" : "复制链接给Ta" }}</span
        >
      </div>
    </div>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import { wechatInitShareConfig, isWxChat } from "@/utils/wxJsSdk";
import { appShare } from "@/utils";
import { rebackUrlPath, formatUrlSearch } from "@/methods/format.js";

export default {
  name: "NoticeShareMask",
  props: {
    target: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      isWxEnv: false,
    };
  },
  components: {},
  computed: {
    ...mapGetters({
      shareInfo: "home/shareInfo",
      showedRisks: "risks/showedRisks",
      productName: "varietyInfo/productName",
    }),
  },
  created() {
    this.isWxEnv = isWxChat();
    document.body.classList.add("van-overflow-hidden");
  },
  mounted() {},
  beforeDestroy() {
    let that = this;
    document.body.removeEventListener("touchmove", that.cancelEvent, {
      passive: false,
    });
    document.body.classList.remove("van-overflow-hidden");
  },
  methods: {
    signNow() {
      this.toSmartHealthy("local");
    },
    cancelClick() {
      this.$emit("close");
    },
    /**分享链接 */
    async copySignLink() {
      let baseLink = "";
      let urlRes = await this.toSmartHealthy("share");
      if (urlRes) {
        baseLink = urlRes;
      } else {
        return;
      }
      let ttText = `尊敬的客户`,
        descText = `邀请您进行${this.productName}产品告知填写`;
      if (this.isWxEnv) {
        const redi = `${window.location.origin}${
          window.location.pathname
        }${formatUrlSearch()}`;
        baseLink = `${redi}&ms_redirect_uri=${encodeURIComponent(
          urlRes
        )}#/healthy`;
        wechatInitShareConfig(`${baseLink}`, `${ttText}`, `${descText}`);
      } else {
        let shareData = {
          icon: `${this.shareInfo.icon}`,
          url: `${baseLink}`,
          title: `${ttText}`,
          desc: `${descText}`,
        };
        appShare(shareData);
      }
    },
    toSmartHealthy(stype = "local") {
      return new Promise((resolve, reject) => {
        const winVal = window.location.hash,
          whash = winVal.split("?");
        let rePath = `${whash[0]}`;
        if (stype == "share") {
          rePath = `&orderNum=${this.orderNum}#/shareres?resvalue=1`;
        } else {
          rePath = `${whash[0]}`;
        }
        let params = {
          ...this.apiComParams,
          addRiskCode: "",
          successUrl: `${rebackUrlPath(rePath)}`,
          failUrl: `${rebackUrlPath(rePath)}`,
        };
        this.$store.commit("insert/UPDATE_PAYINFO", {
          addRiskCode: "",
        });
        // 豁免险种
        const has_hm = this.showedRisks.filter(
          (ele) => ele.productName.indexOf("豁免") !== -1
        );
        // console.log(has_hm);
        if (has_hm.length > 0) {
          let hmCodes = has_hm.map((hm) => hm.productCode || hm.varietyCode);
          if (hmCodes.length > 0) {
            params.addRiskCode = hmCodes.join("-");
            this.$store.commit("insert/UPDATE_PAYINFO", {
              addRiskCode: params.addRiskCode,
            });
          }
        }
        this.$store.commit("updateLoad", true);
        this.$http
          .post(`/ms-insure/api/common/getHealthNoticeUrl`, params, {
            json: true,
          })
          .then(({ data }) => {
            this.$store.commit("updateLoad", false);
            if (data.code === "1" && data.url) {
              this.$emit("refresh");
              if (stype == "share") {
                resolve(data.url);
              } else {
                window.location.href = data.url;
              }
            } else {
              resolve(false);
              this.$toast(data.msg);
            }
          })
          .catch((err) => {
            resolve(false);
            this.$store.commit("updateLoad", false);
          });
      });
    },
  },
};
</script>

<style lang="less" scoped>
.mask {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 25px;

  ._modal {
    width: 100%;
    border-radius: 10px;
    padding: 15px 24px;
    overflow: hidden;
    background: linear-gradient(0deg, #ffeaea 0%, #ffffff 100%);

    ._modal-content {
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 30px;
    }

    ._modal-footer {
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 100%;
      height: 60px;
      font-weight: bold;
      padding: 0 12px;
      font-size: 15px;
      border-radius: 15px;
      background-color: #ffffff;

      .name_c {
        font-size: 16px;
        letter-spacing: 0px;
        line-height: 18px;
        color: rgba(255, 141, 26, 1);
      }

      ._model_btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 46%;
        height: 35px;
        font-size: 15px;
        border-radius: 35px;
        color: #ffffff;
        font-weight: 500;
        background: linear-gradient(270deg, #cb1800 0%, #ff462c 100%);

        &:active {
          opacity: 0.75;
        }
      }
    }
  }
}

.lineh1 {
  font-size: 18px;
  font-weight: bold;
  color: #1b1b1b;
}

.p_label {
  font-size: 12px;
  color: #1b1b1b;
  margin-top: 4px;

  i {
    color: #ff8d1a;
    font-size: 15px;
    font-style: normal;
    font-weight: 600;
  }
}
</style>
